package com.gold.rabbitmqdemo.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 *
 */
public class ConnectionUtils {
    /**
     * 获取rabbitmq连接
     * @return
     * @throws IOException
     * @throws TimeoutException
     */
    public static Connection getConnection() throws IOException, TimeoutException {
        ConnectionFactory factory=new ConnectionFactory();
        //设置访问主机IP、端口
        factory.setHost("47.97.23.184");
        factory.setPort(5672);
        //设置vhost，暂看作是可访问的目录
        factory.setVirtualHost("/vhost_gold");
        //设置登录账号、密码 (user_gold，已通过web页面授权了 /vhost_gold的访问权限)
        factory.setUsername("user_gold");
        factory.setPassword("1234");
        return factory.newConnection();

    }
}
